package Client.Manager
{
	import Client.VO.MapVO;
	
	/**
	 * class		MapMgr
	 * @desc		used to manage the whole map
	 * @author		Aqua
	 * @date		2011-9-7
	 */
	public class MapMgr
	{
		//---------------------//
		//      Singleton      //
		//---------------------//
		
		/**************************************************************************
		 * function				instance getter
		 * @desc				a private function used to enforce singlton
		 * @return	MapMgr		singleton instance of this class
		 *************************************************************************/
		public static function get instance():MapMgr
		{
			if(null == _instance)
			{
				_instance = new MapMgr(singleton);
			}
		
			return _instance;
		}
		
		/**************************************************************************
		 * function			singleton
		 * @desc			a private function used to enforce singlton
		 *************************************************************************/
		private static function singleton():void
		{
			
		}
		
		
		//---------------------//
		//     Constructor     //
		//---------------------//
		
		/**************************************************************************
		 * function			MapMgr
		 * @desc			constructor of class
		 * @param	s		a private function used to enforce singlton
		 *************************************************************************/
		public function MapMgr(s:Function = null):void
		{
			if (singleton != s)
			{
				throw new Error("This is a singleton class!");
			}
		}
		
		
		//-----------------//
		//     Publics     //
		//-----------------//
		
		/**************************************************************************
		 * function			loadMap
		 * @desc			load map's data from xml file
		 * @param	mapID	unique ID of the map
		 *************************************************************************/
		public function loadMap(mapID:String):void
		{
			var mapXML		:XML;
			var mapXMLList	:XMLList;
			var item		:XML;
			
			mapXML		= ResourceMgr.instance.getResource(ResourceMgr.XML_MAP) as XML;
			mapXMLList	= mapXML.map;
			_mapVO		= new MapVO();
			
			for each(item in mapXMLList)
			{
				if (id == item.id)
				{
					initMapVO(_mapVO, item);
					break;
				}
			}
			
			function initMapVO(vo:MapVO, xml:XML):void
			{
				vo.id				= xml.id;
				vo.nameEn			= xml.name_en;
				vo.nameCh			= xml.name_ch;
				vo.minPlayer		= xml.min_player;
				vo.maxPlayer		= xml.max_player;
				vo.maxTurn			= xml.max_turn;
				vo.buildingNumToWin	= xml.building_num_to_win;
				vo.maxWildling		= xml.max_wildling;
				vo.maxToken			= xml.max_token;
				vo.startToken		= xml.start_token;
			}
		}
		
		
		//------------------//
		//     Privates     //
		//------------------//
		
		
		private static var _instance:MapMgr;
		
		private var _mapVO	:MapVO;
	}
	
}